package com.cip.master.action;

import java.util.List;
import java.util.Locale;

import com.cip.admin.model.User;
import com.cip.common.util.SecurityUtil;
import com.cip.master.model.ClassYear;
import com.cip.master.service.ClassYearService;
import com.cip.webapp.action.BaseAction;

public class ClassYearAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	private ClassYear classYear;	
	private ClassYearService classYearService;
	private List<ClassYear> classYears;
	
	public String showClassYearList() throws Exception {
		
		Locale locale = getRequest().getLocale();
		String classYearString = classYearService.getClassYearGridList(locale);
		getRequest().setAttribute("classYearGridString", classYearString);
		
//		setClassYears(classYearService.getAllClassYear());
		return SUCCESS;
	}
	
	public String saveOrUpdateClassYear() throws Exception{
		User user = SecurityUtil.getThreadLocalUser().get();
		classYear.setTenantId(user.getTenantId());
		classYearService.saveOrUpdate(classYear);
		saveMessage(getText("class.added"));
		return SUCCESS;
	}
	
	public String showClassYearForm(){
		setClassYear(new ClassYear());
		return SUCCESS;
	}
	
	public String showEditClassYear() throws Exception{		
		setClassYear(classYearService.getClassYear(classYear.getId()));
		return SUCCESS;
	}
	
	public void setClassYear(ClassYear classYear) {
		this.classYear = classYear;
	}
	public ClassYear getClassYear() {
		return classYear;
	}
	public void setClassYearService(ClassYearService classYearService) {
		this.classYearService = classYearService;
	}
	public ClassYearService getClassYearService() {
		return classYearService;
	}

	public void setClassYears(List<ClassYear> classYearList) {
		this.classYears = classYearList;
	}

	public List<ClassYear> getClassYears() {
		return classYears;
	}

}
